<!-- 确认报名 -->
<template>
	<view class="container">
		<view class="c-module">
			<SignUp :info="{...studentInfo,...signUpInfo}" :key="signUpInfo.amount"></SignUp>
		</view>
		<view class="m-btn">
			<view class="btn-block" v-if="status=='student'">
				<u-button type="primary" text="修改信息" @click="toStudentEditInfo"></u-button>
			</view>
			<view class="btn-block">
				<u-button type="primary" text="确认报名" @click="onPay"></u-button>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import SignUp from "@/pages/components/SignUpInfo.vue"
	export default {
		name: "",
		components: {
			SignUp
		},
		data() {
			return {
				// 报名角色
				apply_type: 0,
				// 用户身份
				status: this.$store.state.status,
				// 报名信息
				signUpInfo: null,
				// 学生信息
				studentInfo: {}
			}
		},
		onLoad(query) {
			if (this.status == 'teacher' || this.status == 'org') {
				this.searchStudentInfo(query.sn)
			}

		},
		onShow() {
			if (this.status == 'student') {
				this.getStudentInfo()
			}
		},
		methods: {
			// 跳转修改信息
			toStudentEditInfo() {
				this.navigateTo("/pages/pages_mine/student/studentEditInfo?type=update")
			},
			// 查询学生信息
			searchStudentInfo(document_nums) {
				this.studentInfo = null
				this.$http.searchStudentInfo({
					document_nums
				}).then(res => {
					this.studentInfo = res
					this.signUpCheck()
				}).catch(err => {
					uni.$u.toast(err.msg)
				})
			},
			// 跳转修改信息
			toStudentInfo() {
				this.navigateTo("/pages/pages_mine/student/studentInfo?type=update")
			},
			// 报名支付
			onPay() {
				let {
					group_id: match_or_exam_id,
					act_song,
					act_duration
				} = uni.getStorageSync("signUpInfo")
				let {
					id: student_id,
					name,
					document_type,
					document_nums,
					document_img,
					organ_name,
					train_teacher_name,
					train_teacher_mobile,
					contact_name,
					contact_mobile,
					contact_address,
					contact_postal_code,
				} = this.studentInfo
				let param = {
					order_type: 1,
					apply_type: this.apply_type,
					match_pay_amount: this.signUpInfo.amount
				}
				let params = {
					student_id,
					name,
					document_type,
					document_nums,
					document_img,
					organ_name,
					train_teacher_name,
					train_teacher_mobile,
					contact_name,
					contact_mobile,
					contact_address,
					contact_postal_code,
					match_or_exam_id,
					act_song,
					act_duration,
					...param
				}
				this.createOrder(params).then(res => {
					this.$refs.uToast.show({
						message: '报名成功',
						type: 'success',
						complete() {
							// uni.navigateBack({
							// 	delta: 3
							// })
							uni.redirectTo({
								url:"./common-page/common-page"
							})
						}
					})
				}).catch(err => {
					this.$refs.uToast.show({
						message: '支付失败',
						type: 'error'
					})

				})
			},
			// 报名校验(取得报名费用)
			signUpCheck() {
				let {
					group_id: match_or_exam_id,
				} = uni.getStorageSync("signUpInfo")
				let {
					id: student_id,
					relatives_id
				} = this.studentInfo
				if (this.status == 'student') {
					if (relatives_id == 0) {
						this.apply_type = 1
					} else if (relatives_id == 1) {
						this.apply_type = 3
					}
				} else if (this.status == 'teacher') {
					this.apply_type = 2
				} else if (this.status == 'org') {
					this.apply_type = 4
				}
				this.$http.gameSignUpCheck({
					order_type: 1,
					apply_type: this.apply_type,
					student_id,
					match_or_exam_id
				}).then(res => {
					this.signUpInfo = uni.getStorageSync("signUpInfo")
					this.signUpInfo.amount = res.amount
				})
			},
			// 获取学生信息
			getStudentInfo() {
				this.$http.getStudentInfo().then(res => {
					this.studentInfo = res
					this.signUpCheck()
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.container {
		.c-info {
			width: 100%;

			.info-one {
				width: 100%;
				height: 260rpx;
				display: flex;
				align-items: center;

				.info-one-avatar {
					width: 40%;
					text-align: center;

					&>image {
						width: 180rpx;
						height: 240rpx;
					}
				}

				.info-one-content {
					display: flex;
					flex-direction: column;
					line-height: 60rpx;
				}
			}

			.info-two {
				width: 100%;
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0;
				overflow: hidden;
				box-sizing: border-box;
				border-top: 1rpx solid #aaa;
				border-bottom: 1rpx solid #aaa;

				.info-two-block {
					display: flex;
					flex-direction: column;

					&>text {
						&:first-child {
							color: #aaa;
						}
					}
				}
			}

			.info-three {
				width: 100%;
				border-top: none;

				.info-two-block {
					&:nth-child(1) {
						width: 45%;
					}

					&:nth-child(2) {
						width: 25%;
					}

					&:nth-child(3) {
						width: 30%;
						word-break: break-all;
					}
				}

			}

			.info-four {
				width: 100%;
				padding: 30rpx 0;

				.info-four-block {
					line-height: 80rpx;
				}
			}

		}


	}
</style>
